<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 时间和空间复杂度都是 On -->
</head>
<body>
    <script>
        var RecentCounter = function() {
            this.q = []; // 把队列挂在this上
        };

        /** 
         * @param {number} t
         * @return {number}
         */
        RecentCounter.prototype.ping = function(t) {
            this.q.push(t);
            while(this.q[0] < t - 3000) {
                this.q.shift(); // 出队
            }
            return this.q.length;
        };
    </script>
</body>
</html>